





    <style>
        .datagrid-row {
            height: 42px;
            text-align: center;
        }
    </style>

<table id="dg" class="easyui-datagrid" title="<?= $project['name'] ?>翻译录入"
       style="width:100%; height:100%; margin-left: 20px; margin-right: 20px"


</table>








<script>


    $(function () {

        $("input[name='cb_column']").click(function () {

            var column = $(this).val();

            if ($(this).get(0).checked) {
                $('#dg').datagrid(
                    'showColumn', column
                );

            } else {
                $('#dg').datagrid(
                    'hideColumn', column
                );

            }

        });


        $("#btn_key").click(function () {
            window.open("<?= base_url('admin/key/keys?pid=') ?>" + pid, 'KEY', 'fullscreen=1, channelmode= 1,location=0, menubar=no');
        });

        $("#btn_submit_version").click(function () {
            $('#submitversionModal').modal('show');
        });


        // 历史版本
        $("#btn_history_version").click(function () {

            $.get("<?= base_url('admin/version/project_version?pid=') ?>"+pid, function (res) {
                $("#versionHistoryModal .modal-body").html(res);
                $("#versionHistoryModal").modal({keyboard: false, show: true});
            })
        });


        var icon = "<i class='fa fa-times-circle'></i> ";



        //提交版本
        $("#submitversion_form").validate({
            rules: {
                vremark: {
                    required: true
                }
            },

            messages: {
                vremark: icon + "请输入版本备注"
            },

            submitHandler: function (form) {

                var vremark = $("#vremark").val();

                if (vremark == "") {
                    parent.layer.msg('请输入版本描述', {shift: 6});
                    return;
                }

                var lang = new Array();
                $("input[name='sub_lang_ids']:checked").each(function (index, element) {

                    var langid = $(this).val();
                    lang.push(
                        langid
                    );
                });


                if (lang.length == 0) {
                    parent.layer.msg('请选择要提交的语言', {shift: 6});
                    return;
                }


                var lang_json = JSON.stringify(lang);


                $.post('<?= base_url("admin/version/submitversion") ?>',
                    {
                        "remark": vremark,
                        'lang_ids': lang_json,
                        'pid': pid
                    }

                    ,
                    function (res) {
                        if (res.code == 200) {
                            $('#submitversionModal').modal('hide');
                            toastr.success("提交版本成功!", '提示');
                        } else {
                            toastr.error(res.msg, '提示');
                        }

                    }, "json");

            }
        });



    });
    var grid = $('#dg').datagrid({
        data: <?=$data ?>,
        columns: [<?=$columnsjson ?>],
        singleSelect: true,
        onClickCell: onClickCell,
        iconCls: 'icon-edit',
        showHeader: true,
        editorHeight: 50,
        fitColumns: true,
        rownumbers: true,
        fit: true,


        onEndEdit: function (index, row) {

            var rowJson = JSON.stringify(row);
            $.post("<?= base_url("admin/content/submitcontent") ?>",
                {
                    "row": rowJson,
                    "pid": pid
                },


                function (res) {

                    if (res.code == 200) {
                        // toastr.success("创建成果成功", '提示');
                        //window.location.href = '<?= base_url("admin/project/projects") ?>';
                    } else {

                        alert(res.msg);

                    }

                }, "json");

        }

    });


    $.extend($.fn.datagrid.methods, {

        editCell: function (jq, param) {

            return jq.each(function () {

                var opts = $(this).datagrid('options');

                var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));

                for (var i = 0; i < fields.length; i++) {
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor1 = col.editor;
                    if (fields[i] != param.field) {
                        col.editor = null;
                    }
                }

                $(this).datagrid('beginEdit', param.index);

                for (var i = 0; i < fields.length; i++) {
                    var col = $(this).datagrid('getColumnOption', fields[i]);
                    col.editor = col.editor1;
                }
            });
        }
    });


    $.extend($.fn.datagrid.defaults.editors, {
        text: {
            init: function (container, options) {
                //var input = $(' <textarea class="datagrid-editable-input" style="vertical-align: middle; height: 50px; width: 189px;"></textarea>').appendTo(container);


                // var textArea = ' <textarea class="datagrid-editable-input" style="vertical-align: middle; height: 50px; width: 189px;"></textarea>';

                return input;
            },
            destroy: function (target) {
                $(target).remove();
            },
            getValue: function (target) {
                return $(target).val();
            },
            setValue: function (target, value) {
                $(target).val(value);


            },
            resize: function (target, width) {
                $(target)._outerWidth(width);
            }
        }
    });


    var editIndex = undefined;
    function endEditing() {


        if (editIndex == undefined) {
            return true
        }
        if ($('#dg').datagrid('validateRow', editIndex)) {
            $('#dg').datagrid('endEdit', editIndex);
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickCell(index, field) {
        if (endEditing()) {
            $('#dg').datagrid('selectRow', index)
                .datagrid('editCell', {index: index, field: field});
            editIndex = index;
        }
    }


    var i = 0;


    function hideColumnText() {

        if (i % 2 == 0) {
            $('#dg').datagrid(
                'hideColumn', 'key'
            );
        } else {

            $('#dg').datagrid(
                'showColumn', 'key'
            );

        }
        i++;
    }






</script>
